package cn.jhc.sevlet;//修改学生信息

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.Clazz;
import cn.jhc.bean.Student;
import cn.jhc.dao.ClassDao;
import cn.jhc.dao.StudentDao;
import cn.jhc.dao.impl.ClassDaoImpl;
import cn.jhc.dao.impl.StudentDaoImpl;

/**
 * Servlet implementation class AlterinfoServlet
 */
@WebServlet("/user/teacher/alterinfo.do")
public class AlterinfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AlterinfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		StudentDao studentDao = new StudentDaoImpl();		
		int sid = Integer.valueOf(request.getParameter("sid"));
		String sno = request.getParameter("sno");
//		String id = studentDao.get("sno");
		String sname = request.getParameter("sname");
		String sex = request.getParameter("sex");
		String cardid = request.getParameter("cardid");
		String clazzname = request.getParameter("classname");
		ClassDao classDao = new ClassDaoImpl();
		List<Clazz> clazzs = classDao.list(clazzname);
		
		Clazz clazz = clazzs.get(0);
		String college = request.getParameter("college");
		Student student = new Student();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");	
		System.out.println("save0!!!!!!!!!!!!!!!!!!!!!");
		System.out.println(request.getParameter("entertime"));
		try {
			Date entertime = sdf.parse(request.getParameter("entertime"));
			Date gradtime = sdf.parse(request.getParameter("gradtime"));
			student.setEntertime(entertime);
			student.setGradtime(gradtime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("save1!!!!!!!!!!!!!!!!!!!!!");
		student.setId(sid);
		student.setSpassword("123456");
		student.setSno(sno);
		student.setSname(sname);
		student.setSex(sex);
		student.setCardid(cardid);
		student.setClazz(clazz);
		System.out.println("save!!!!!!!!!!!!!!!!!!!!!");
		studentDao.update(student);
		response.sendRedirect("./tinformation.do");
	}

}
